define('jForumTemplate', [
    'require',
    'jquery',
    'jForumUtils',
    'jForumMember',
    'Mustache',
    'lazyload',
    'select2'
], function (require, $, util, member, Mustache, lazyload, select2) {
    'use strict';

    var jForumTemplate = (function () {
        var tmp = {};
        //主页侧边栏的版块统计[NW][1]
        tmp.buildIndexSideBoardStats = function (json, element) {
            var data = {};
            data.result = json;
            var T = '{#result}'
                + '<div class="side-stats-item">'
                + '  <a href="{APP}{link}">{title}</a> <span class="float-right">{topices}/{postses}</span>'
                + '</div>'
                + '{/result}';
            Mustache.parse(T, ['{', '}']);
            $(element).append(Mustache.render(T, $.extend(data, { "APP": BASE })));
        };
        //版块列表边栏的会员标兵[NW][2]
        tmp.buildModelMember = function (json, element) {
            var data = {};
            data.result = json;
            var T = '{#result}'
                + '<div class="side-stats-item">'
                + '  <a href="{URI}">{title}</a><span class="float-right">{value}</span>'
                + '</div>'
                + '{/result}';
            var rs = {
                URI: function () {
                    return BASE + '/member/' + this.id + '.xhtml';
                }
            };
            Mustache.parse(T, ['{', '}']);
            $(element).append(Mustache.render(T, $.extend(data, rs)));
        };
        //部分页面右侧边栏的话题列表[NW][3]
        tmp.buildRightSectionTopic = function (json, element) {
            var data = {};
            data.result = json;
            var T = '{#result}'
                + '<div class="side-topic-item">'
                + '  <a class="side-topic-item-link" href="{APP}{link}">{title}</a>'
                + '  <span class="sidebar-recent-author"><a href="{APP}/member/{author}.xhtml">{authorNames}</a></span>'
                + '  <span class="sidebar-recent-content">&#187; {date}</span>'
                + '</div>'
                + '{/result}';

            Mustache.parse(T, ['{', '}']);
            $(element).append(Mustache.render(T, $.extend(data, { "APP": BASE })));
        };
        //会员中心的话题[NW][4]
        tmp.drawDynamicTopic = function (json, element) {
            if ($.isEmptyObject(json)) {
                return;
            }
            $('#forumlist').removeClass('sectionbox');
            var data = {};
            data.result = json;
            var T = '{#result}'
                + '<div class="media mc-topic">'
                + '  <div class="media-left">'
                + '    <a href="{APP}/member/{author}.xhtml" title="{authorNames}">'
                + '        <img class="media-object img-circle" src="{APP}/member/avatar/{author}.png" style="width: 64px; height: 64px;">'
                + '    </a>'
                + '  </div>'
                + '  <div class="media-body mc-topic-body">'
                + '    <a href="{APP}{link}" class="forum-article-header">{title}</a>'
                + '    <p><a href="{APP}/member/{author}.xhtml" title="会员主页">{authorNames}</a>&nbsp;&#187;&nbsp;{date}'
                + '       <span class="float-right">&nbsp;<a href="{APP}{boardLink}">{boardTitle}</a></span>'
                + '    </p>'
                + '    <div class="mc-topic-body-txt">{description}</div>'
                + '  </div>'
                + '</div>{/result}';
            Mustache.parse(T, ['{', '}']);
            $(element).append(Mustache.render(T, $.extend(data, { "APP": BASE })));
        };
        //会员主页的版块星标[NW][5]
        tmp.buildMemberStarBoard = function (json, element) {
            if ($.isEmptyObject(json)) {
                return;
            }
            $('#forumlist').removeClass('sectionbox');
            var data = {};
            data.result = json;
            var T = ''
                + '<ul class="list-inline">{#result}'
                + '  <li class="list-inline-item"><a href="{APP}{link}" class="focus-board">{title}</a></li>'
                + '{/result}</ul>';
            Mustache.parse(T, ['{', '}']);
            $(element).append(Mustache.render(T, $.extend(data, { "APP": BASE })));
        };
        //版块内容页的版主列表[NW][6]
        tmp.drawBoardModeratorList = function (json, element) {
            var data = {};
            data.result = json;
            var T = ''
                + '<ul class="list-inline" id="board-moderator">{#result}'
                + '  <li class="list-inline-item"><a href="{APP}/member/{id}.xhtml">{title}</a></li>'
                + '{/result}</ul>';
            Mustache.parse(T, ['{', '}']);
            $(element).append(Mustache.render(T, $.extend(data, { "APP": BASE })));
        };
        //版块内容页的置顶话题列表[NW][7]
        tmp.drawBoardTopSectionTopic = function (data, element) {
            var currentId = "dynamic-section-" + util.randomAlphaNumeric(8);
            $(element).attr('id', currentId);var _curIns = this;
            $.each(data, function (index, item) {
                _curIns.drawUpdatedTopics(item, currentId, false);
            });
        };
        // 聊天页中的历史记录[NW][8]
        tmp.drawLetterHistoryMessage = function (json, jqEle) {
            var T = ''
                + '<div class="media{#master} media-master{/master}" id="letter-{id}">'
                + '  <div class="media-avatar media-left">'
                + '    <a href="javascript:;">'
                + '        <img class="media-object img-circle" src="{APP}/member/avatar/{sender}.png" style="height:64px;width:64px;">'
                + '    </a>'
                + '  </div>'
                + '  <div class="media-body">'
                + '    <div class="media-bubble">'
                + '        <h6 class="media-heading"><small>{datetime}</small></h6>'
                + '        {#SM}<strong>{subject}</strong>{/SM}'
                + '        <p>{&body}</p>'
                + '    </div>'
                + '  </div>'
                + '</div>';
            var rs = {
                SM: function () {
                    return this.sender == 0;
                },
                APP: BASE
            };
            Mustache.parse(T, ['{', '}']);
            var ext = $.extend(json, rs);
            //
            $(Mustache.render(T, ext)).insertAfter($('#' + jqEle).find('p.text-center'));
        };
        //大版主列表
        tmp.drawBoardGroupModeratorList = function (json, element) {
            var data = {};
            data.result = json;
            var T = ''
                + '{#result}'
                + '  <dl class="d-inline-block p-2"><dt><img src="{APP}/member/avatar/{id}.png" width="32px" height="32px"/></dt><dd><a href="{APP}/member/{id}.xhtml">{title}</a></dd></dl>'
                + '{/result}';
            Mustache.parse(T, ['{', '}']);
            $(element).append(Mustache.render(T, $.extend(data, { "APP": BASE })));
        };
        //话题的快速回复
        tmp.buildRichEditor = function (jqEle) {
            jqEle.find('[data-richEditor="CKEditor"]').trigger('initEvent');
        };
        tmp.buildEditorMessage = function (errJson) {
            //在线吗
            var cam = member.get();
            var t = '<div class="topic_posts_item main-color">'
                + '  <dl class="topic_posts_item_left">'
                + '    <dt style="padding-top: 20px;padding-left: 20px;width:180px">'
                + '      <div class="posts-member-avatar">'
                + '        <div class="avatar">'
                + '          <img class="avatar" src="' + BASE + '/avatar/empty.png" alt="User avatar" />'
                + '        </div>'
                + '      </div>'
                + '    </dt>'
                + '  </dl>'
                + '  <div class="topic_posts_item_right h260">'
                + '    <div class="posts-body">'
                + '      <h5 class="hl45 default-txt-color">快速回复</h5>'
                + '      <div id="block-paper">'
                + '        <p>' + errJson.message;
            if ($.isEmptyObject(cam) || parseInt(cam.id) < 1) {
                t += ' &nbsp; <a href="' + BASE + '/member/login">登录</a>&nbsp; | &nbsp;<a href="' + BASE + '/member/register">注册</a>';
            }
            t += '      </p></div>'
                + '    </div>'
                + '  </div>'
                + '</div>'
            $('#quick_reply_posts').removeClass('ld-over running').find('div.ld').remove();
            $('#quick_reply_posts').append(t);
        };
        tmp.drawThreads = function (jsonArray) {
            var targetEleSelector = $('#board_topic_collect');
            targetEleSelector.find('.dynamic-topic-record').remove();
            var obj = {};
            obj.result = jsonArray;
            var T = '{#result}'
                + '<li class="board_item dynamic-topic-record">'
                + '  <dl class="icon topic_{status}">'
                + '    <dt>'
                + '      <div class="board_item_title">'
                + '        <article class="forum-article-header">'
                + '            {#oneDay}<span class="label" title="新鲜的">&#x1F31F</span> {/oneDay}'
                + '            {#top}<span class="label" title="置顶话题">&#x1F4CC</span> {/top}'
                + '            {#best}<span class="label" title="精华话题">&#x1F48E</span> {/best}'
                + '            {#image}<span class="label" title="图片话题">&#x1F304</span> {/image}'
                + '            {#hot}<span class="label" title="很火噢">&#x1F525</span> {/hot}'
                + '            <a href="{APP}{boardLink}?category={categoryKey}">[{category}]</a> '
                + '            <a href="{APP}{link}" class="forumtitle">{title}</a>'
                + '        </article>'
                + '        <a class="txtline" href="{APP}/member/{author}.xhtml">{authorNames}</a> &#187; {date}'
                + '      </div>'
                + '    </dt>'
                + '    <dd class="replies wp10 stats-item">{replies}<dfn>Replies</dfn></dd>'
                + '    <dd class="views wp10 stats-item">{views}<dfn>Views</dfn></dd>'
                + '    <dd class="latest">{#recent}'
                + '      <span class="last-posts-avatar">'
                + '        <img src ="{APP}/member/avatar/{recentAuthor}.png" width="32px" height="32px"/>'
                + '      </span>'
                + '      <span class="last-posts">'
                + '        <a href="{APP}/member/{recentAuthor}.xhtml" class="latest-member-color">{recentAuthorNames}</a>'
                + '        <br/>'
                + '        {recentDate}'
                + '      </span>{/recent}'
                + '    </dd>'
                + '  </dl>'
                + '</li>{/result}';
            var extRS = {
                recent: function () {
                    return parseInt(this.recentAuthor) > 0;
                },
                APP: BASE
            };
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(obj, extRS);
            targetEleSelector.append(Mustache.render(T, rs));
        };
        //顶部的会员面板@20200502
        tmp.drawMemberPanel = function (json, jqEle) { //[NW]
            if ($.isEmptyObject(json) || parseInt(json.id) <= 0) { //游客跳过
                return;
            }
            var I = '<a href="{APP}/message/" role="button" class="btn btn-light">'
                + '<i class="mdi mdi-notifications" aria-hidden="true"></i>'
                + '<sup id="notification" class="d-none badge">0</sup>'
                + '</a>'
                + '<a role="button" class="btn btn-light" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" href="{APP}">{nickname}</a>'
                + '<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">'
                + '<span class="sr-only">Toggle Dropdown</span>'
                + '</button>'
                + '<div class="dropdown-menu">'
                + '<a class="dropdown-item" href="{APP}/member/home/">个人中心</a>'
                + '<div class="dropdown-divider"></div>'
                + '<a class="dropdown-item" href="{APP}/member/home/profile">帐户设置</a>'
                + '<a class="dropdown-item" href="{APP}/message/">消息</a>'
                + '<div class="dropdown-divider"></div>'
                + '<a class="dropdown-item" href="{APP}/member/offline.xhtml?trace=msa">注销</a>'
                + '</div>';
            Mustache.parse(I, ['{', '}']);
            var rs = $.extend(json, { "APP": BASE });
            jqEle.attr('data-ux', util.getUnixStamp()).find('a.forum_member_defat_link').remove();
            jqEle.append(Mustache.render(I, rs)).attr('data-member', json.id);
            //
            member.panelRenderDefer(json);
        };
        //部分页面的右侧边栏的会员信息
        tmp.drawMemberInfo = function (json, jqEle) {
            var F = ''
                + '<div style="padding-top:30px;">'
                + '  <div class="text-center" style="height:auto;">'
                + '     <a href="{APP}/member/{id}.xhtml" title="会员主页"><img class="img-circle" src="{APP}/member/avatar/{id}.png" style="width:100px;height:100px"/></a>'
                + '  </div>'
                + '  <div class="text-center member_embed_info">'
                + '    <h5><a href="{APP}/member/home/" title="会员中心" class="member-{style}">{nickname}</a></h5>'
                + '    <div class="row">'
                + '    <dl class="col-xs-6 col-sm-4"><dt>{status}</dt><dd>状态</dd></dl>'
                + '    <dl class="col-xs-6 col-sm-4"><dt>{group}</dt><dd>组</dd></dl>'
                + '    <dl class="col-xs-6 col-sm-4"><dt>{role}</dt><dd>角色</dd></dl>'
                + '    </div>'
                + '  </div>'
                + '</div>';
            Mustache.parse(F, ['{', '}']);
            var rs = $.extend(json, { "APP": BASE });
            jqEle.find('form').remove();
            jqEle.append(Mustache.render(F, rs));
        };
        //会员欢迎页的版块收藏[NW]
        tmp.buildMemberFavoriteBoard = function (json, element) {
            if ($.isEmptyObject(json)) {
                return;
            }
            var data = {};
            data.result = json;
            var T = ''
                + '<ul class="fav-board-collect">{#result}'
                + '  <li class="fav-board-item">'
                + '    <div class="fav-board-logo">'
                + '        <img src="{APP}/board/ico/{id}.png" />'
                + '        <p><a href="{link}">{title}</a></p>'
                + '    </div>'
                + '    <div class="fav-board-stats">'
                + '      <dl><dt>话题</dt><dd>{topices}</dd></dl>'
                + '      <dl><dt>回复</dt><dd>{postses}</dd></dl>'
                + '    </div>'
                + '  </li>'
                + '{/result}</ul>';
            Mustache.parse(T, ['{', '}']);
            $(element).append(Mustache.render(T, $.extend(data, { "APP": BASE })));
        };
        //个人中心的受欢迎的回调
        tmp.basicThreadTemplate = function (jsonArray) {
            var targetEleSelector = $('#member-publish-topic');
            var obj = {};
            obj.result = jsonArray;
            var T = '{#result}'
                + ' <div class="media mc-topic">'
                + '   <div class="media-left">&nbsp;</div>'
                + '   <div class="media-body mc-topic-body">'
                + '     <article class="forum-article-header"><a href="{APP}{link}" class="forumtitle">{title}</a></article>'
                + '     <p>'
                + '       <a href="{APP}{publisherURI}" title="会员主页">{publisher}</a> &#187; {publishDate}'
                + '       <span class="float-right">'
                + '         <a href="{APP}{boardURI}">{boardName}</a>'
                + '       </span>'
                + '     </p>'
                + '     <div class="topic_item_body_footer">'
                + '       <ul class="list-inline mc-topic-panel">'
                + '         <li class="list-inline-item"><span><i class="ico-sm ico-color-link mdi mdi-comment" aria-hidden="true"></i>&nbsp;&nbsp;{postses}</span></li>'
                + '         <li class="list-inline-item"><span><i class="ico-sm ico-color-teal mdi mdi-thumb-up" aria-hidden="true"></i>&nbsp;&nbsp;{likes}</span></li>'
                + '         <li class="list-inline-item"><span><i class="ico-sm ico-color-red mdi mdi-favorite" aria-hidden="true"></i>&nbsp;&nbsp;{favorites}</span></li>'
                + '         <li class="list-inline-item"><span><i class="ico-sm mdi mdi-eye" aria-hidden="true"></i>&nbsp;&nbsp;{displaies}</span></li>'
                + '       </ul>'
                + '     </div>'
                + '   </div>'
                + ' </div>{/result}';
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(obj, { "APP": BASE });
            targetEleSelector.append(Mustache.render(T, rs));
        };
        //首页话题列表加载像册的回调
        tmp.packAlbumHoldSection = function (json) {
            if ($.isEmptyObject(json)) {
                return;
            }
            $('div[data-album]').each(function () {
                var tmpBody = $(this);
                var aid = tmpBody.attr('data-album');
                var rs = {};
                rs.result = json[aid];

                var T = '<ul class="list-inline album-thumb">'
                    + '{#result}'
                    + '   <li class="list-inline-item"><a href="{link}" data-toggle="lightbox" data-title="{caption}" data-gallery="threads-{album}-gallery" data-type="image"><img class="lazyload" src="" data-original="{thumbnail}"/></a></li>'
                    + '{/result}'
                    + ' </ul>';
                Mustache.parse(T, ['{', '}']);
                tmpBody.append(Mustache.render(T, rs)).find('img.lazyload').lazyload();
            });
        };
        //版块首页加载版块的统计
        tmp.loadBoardStatsResult = function (json, element) {
            if ($.isEmptyObject(json.result)) {
                return;
            }
            $.each(json.result, function (index, item) {
                var tb = $('[data-board="' + item.board + '"]');
                tb.find('.threads').html(item.topices);
                tb.find('.replies').html(item.postses);
                tb.find('.today-counter').html('(' + item.todayTopics + ')');
                //游客操作的不显示
                if (parseInt(item.recentAuthor) > 0) {
                    var T = ''
                        + '<dfn>Last posts</dfn>'
                        + '<a href="{APP}{recentLink}" title="{recentTitle}" class="lastsubject">{recentTitle}</a> '
                        + '<a href="{APP}/member/{recentAuthor}.xhtml" class="latest-member-color">{recentAuthorNames}</a> &#187; {recentDate}';
                    Mustache.parse(T, ['{', '}']);
                    var rs = $.extend(item, { "APP": BASE });
                    tb.find('.latest').append(Mustache.render(T, rs));
                }
            });
        };
        //话题|版块的工具菜单
        tmp.buildMenuList = function (json) {
            var jqEle = $('#' + json.element);
            var T = ''; var tmpSize = 1; var kt = Object.keys(json.result).length;

            $.each(json.result, function (key, value) { //公共|私有
                $.each(value, function (index, item) { //连接
                    var tmp;
                    if (item.ajax) {
                        tmp = '<a href="javascript:;" class="dropdown-item action-cmd" data-handler="%URL%">%UA%</a>';
                    } else {
                        tmp = '<a class="dropdown-item" href="%URL%" target="_blank">%UA%</a>';
                    }
                    T += tmp.replace('%URL%', BASE + item.uri).replace('%UA%', item.anchor);
                });
                if (kt > tmpSize) {
                    T += '<div class="dropdown-divider"></div>';
                }
                tmpSize += 1;
            });
            jqEle.append(T);
        };
        //底部的版块导航
        tmp.buildBoardNavigateSelect = function (json) {
            //生成select
            var selectEleWrox = $('#' + json.element);
            var selectEle = $('<select class="form-control" aria-hidden="true"></select>').appendTo(selectEleWrox);
            //
            var selectData = new Array();
            $.each(json.result, function (key, value) {
                var dataItem = {};
                dataItem.text = key;
                dataItem.children = new Array();
                $.each(value, function (innerIndex, innerObj) {
                    $.each(innerObj, function (attrName, attrValue) {
                        dataItem.children.push({ id: attrName, text: attrValue });
                    });
                });
                selectData.push(dataItem);
            });
            var sob = selectEle.select2({
                theme: 'bootstrap4',
                data: selectData
            });
            sob.on("select2:select", function (e) {
                //选中的值是?
                var selectBoard = e.params.data.id;
                if (selectBoard && !util.isBlank(selectBoard)) {
                    window.location.href = BASE + '/board/' + selectBoard + '.xhtml';
                }
            });
            //显示
            selectEleWrox.find('p.board-navigator-select').remove();
            sob.select2("open");
        };
        tmp.drawCarousel = function(json, jqEle){
            var rs={};
                rs.result = json;
                rs.size = json.length;
            var T=''
                 +'<div id="carousel-example-generic" class="carousel slide" data-ride="carousel" style="width:749px">'
                 +'  <ol class="carousel-indicators">';
            for (i = 0; i < rs.size; i++) { 
                T+='    <li data-target="#carousel-example-generic" data-slide-to="'+i+'"'; 
                if(i==0){
                    T+=' class="active"';
                }
                T+='></li>';
            }
            T +='  </ol>'
              +'  <div class="carousel-inner" role="listbox">{#result}'
              +'    <div class="carousel-item{#first} active{/first}">'
              +'      <img src="{imageAddr}" alt="{caption}">'
              +'      <div class="carousel-caption"><a href="{link}">{caption}</a></div>'
              +'    </div>{/result}'
              +'  </div>'
              +'  <a class="carousel-control-prev" href="#carousel-example-generic" role="button" data-slide="prev">'
              +'    <span class="carousel-control-prev-icon" aria-hidden="true"></span>'
              +'    <span class="sr-only">Previous</span>'
              +'  </a>'
              +'  <a class="carousel-control-next" href="#carousel-example-generic" role="button" data-slide="next">'
              +'    <span class="carousel-control-next-icon" aria-hidden="true"></span>'
              +'    <span class="sr-only">Next</span>'
              +'  </a>'
              +'</div>';
            
            Mustache.parse(T, ['{', '}']);
            jqEle.append(Mustache.render(T, rs));
            $('.carousel').carousel();
        };
        //最新类推送回调
        tmp.drawUpdatedTopics = function(json, jqEle, isPushed){
            var topicItemCS = isPushed?'dynamic-topic-record fadeout-anim':'updated-rows';
            var UT='' 
                +'<li class="board_item '+topicItemCS+'">' 
                +'  <dl class="icon topic_{status}">' 
                +'    <dt>' 
                +'      <div class="board_item_title">' 
                +'        <article class="forum-article-header">' 
                +'          {#oneDay}<span class="label" title="新鲜的">&#x1F31F</span> {/oneDay}' 
                +'          {#top}<span class="label" title="置顶话题">&#x1F4CC</span> {/top}' 
                +'          {#best}<span class="label" title="精华话题">&#x1F48E</span> {/best}' 
                +'          {#image}<span class="label" title="图片话题">&#x1F304</span> {/image}' 
                +'          {#hot}<span class="label" title="很火噢">&#x1F525</span> {/hot}'
                +'          <a href="{APP}{boardLink}?category={categoryKey}">[{category}]</a> '
                +'          <a href="{APP}{link}" class="forumtitle">{title}</a>' 
                +'        </article>' 
                +'        <a class="txtline" href="{APP}/member/{author}.xhtml">{authorNames}</a> &#187; {date}' 
                +'      </div>' 
                +'    </dt>' 
                +'    <dd class="replies wp10 stats-item">{replies}<dfn>Replies</dfn></dd>' 
                +'    <dd class="views wp10 stats-item">{views}<dfn>Views</dfn></dd>' 
                +'    <dd class="latest">{#recent}' 
                +'      <span class="last-posts-avatar"><img src ="{APP}/member/avatar/{recentAuthor}.png" width="32px" height="32px"/></span>' 
                +'      <span class="last-posts"><a href="{APP}/member/{recentAuthor}.xhtml" class="latest-member-color">{recentAuthorNames}</a> ' 
                +'      <br/>{recentDate}</span>{/recent}' 
                +'    </dd>' 
                +'  </dl>' 
                +'</li>';
            var UE='' 
                +'<li class="board_item '+topicItemCS+'">' 
                +'  <dl class="icon topic_{status}">' 
                +'    <dt>' 
                +'      <div class="board_item_title">' 
                +'        <article class="forum-article-header">' 
                +'          {#oneDay}<span class="label" title="新鲜的">&#x1F31F</span> {/oneDay}' 
                +'          {#top}<span class="label" title="置顶话题">&#x1F4CC</span> {/top}' 
                +'          {#best}<span class="label" title="精华话题">&#x1F48E</span> {/best}' 
                +'          {#image}<span class="label" title="图片话题">&#x1F304</span> {/image}' 
                +'          {#hot}<span class="label" title="很火噢">&#x1F525</span> {/hot}'
                +'          <a href="{APP}{boardLink}?category={categoryKey}">[{category}]</a> '
                +'          <a href="{APP}{link}" class="forumtitle">{title}</a>' 
                +'        </article>' 
                +'        <a class="txtline" href="{APP}/member/{author}.xhtml">{authorNames}</a> &#187; {date}' 
                +'      </div>' 
                +'    </dt>' 
                +'    <dd class="replies wp10 stats-item">{replies}<dfn>Replies</dfn></dd>' 
                +'    <dd class="views wp10 stats-item">{views}<dfn>Views</dfn></dd>' 
                +'    <dd class="latest"></dd>' 
                +'  </dl>' 
                +'</li>';
            var extRS={
                recent : function(){
                    return parseInt(this.recentAuthor) > 0;
                },
                APP : BASE
            };
            var T = (json.recentAuthorNames !== '0.0.0.*')?UT:UE;
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(json, extRS);
            //
            $('#'+jqEle).prepend(Mustache.render(T, rs));
        };
        //版块话题的动态加载回调函数
        tmp.drawThreads = function (jsonArray) {
            var targetEleSelector = $('#board_topic_collect');
            targetEleSelector.find('.dynamic-topic-record').remove();
            var obj = {};
            obj.result = jsonArray;
            var T = '{#result}'
                + '<li class="board_item dynamic-topic-record">'
                + '  <dl class="icon topic_{status}">'
                + '    <dt>'
                + '      <div class="board_item_title">'
                + '        <article class="forum-article-header">'
                + '            {#oneDay}<span class="label" title="新鲜的">&#x1F31F</span> {/oneDay}'
                + '            {#top}<span class="label" title="置顶话题">&#x1F4CC</span> {/top}'
                + '            {#best}<span class="label" title="精华话题">&#x1F48E</span> {/best}'
                + '            {#image}<span class="label" title="图片话题">&#x1F304</span> {/image}'
                + '            {#hot}<span class="label" title="很火噢">&#x1F525</span> {/hot}'
                + '            <a href="{APP}{boardLink}?category={categoryKey}">[{category}]</a> '
                + '            <a href="{APP}{link}" class="forumtitle">{title}</a>'
                + '        </article>'
                + '        <a class="txtline" href="{APP}/member/{author}.xhtml">{authorNames}</a> &#187; {date}'
                + '      </div>'
                + '    </dt>'
                + '    <dd class="replies wp10 stats-item">{replies}<dfn>Replies</dfn></dd>'
                + '    <dd class="views wp10 stats-item">{views}<dfn>Views</dfn></dd>'
                + '    <dd class="latest">{#recent}'
                + '      <span class="last-posts-avatar">'
                + '        <img src ="{APP}/member/avatar/{recentAuthor}.png" width="32px" height="32px"/>'
                + '      </span>'
                + '      <span class="last-posts">'
                + '        <a href="{APP}/member/{recentAuthor}.xhtml" class="latest-member-color">{recentAuthorNames}</a>'
                + '        <br/>'
                + '        {recentDate}'
                + '      </span>{/recent}'
                + '    </dd>'
                + '  </dl>'
                + '</li>{/result}';
            var extRS = {
                recent: function () {
                    return parseInt(this.recentAuthor) > 0;
                },
                APP: BASE
            };
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(obj, extRS);
            targetEleSelector.append(Mustache.render(T, rs));
        };
        //话题回复的动态加载回调函数
        tmp.drawReplier = function (jsonArray) {
            var targetEleSelector = $('#topic_posts_collect');
            targetEleSelector.find('.dynamic-posts-record').remove();
            var obj = {};
            obj.result = jsonArray;

            var T = '{#result}'
                + '<div class="topic_posts dynamic-posts-record">'
                + '  <div class="topic_posts_item">'
                + '    <dl class="topic_posts_item_left" data-handler="{APP}/member/profile.json?id={author}">'
                + '      <dt style="padding-top: 20px;padding-left: 20px;width:180px">'
                + '        <div class="posts-member-avatar">'
                + '          <a href="javascript:;" class="avatar poper-member-menu">'
                + '            <img class="avatar" src="{APP}/member/avatar/{author}.png" alt="User avatar" />'
                + '          </a>'
                + '        </div>'
                + '        <a href="{APP}/member/{author}.xhtml" class="member-info"> <span class="member-{author}-label member-{authorStyle}">{authorNames}</span></a>'
                + '      </dt>'
                + '      <dd>{authorGroup}</dd>'
                + '      {#master}<dd><small class="badge badge-dark">楼主</small></dd>{/master}'
                + '    </dl>'
                + '    <div class="topic_posts_item_right">'
                + '      <div id="posts-{id}" class="posts-body">'
                + '        <ul class="posts-buttons">'
                + '          <li><a href="javascript:;" class="action-cmd delete-post" data-handler="{APP}/posts/delete" data-query="id:{id}"><i class="ico-sm mdi mdi-delete" aria-hidden="true"></i><span>删除</span></a></li>'
                + '          <li><a href="javascript:;" class="post-action-quote" data-handler="{APP}/posts/quote/data.json" data-query="id:{id}"><i class="ico-sm mdi mdi-quote"></i><span>回复</span></a></li>'
                + '          <li><a href="javascript:;" class="post-action-report" data-handler="{APP}/posts/report" data-query="id:{id}"><i class="ico-sm mdi mdi-flag"></i><span>举报</span></a></li>'
                + '          <li><a name="#posts-{id}">{floor}<sup>#</sup></a></li>'
                + '        </ul>'
                + '        <p class="posts-member">'
                + '          <a href="{APP}/member/{author}.xhtml">{authorNames} @u{author}</a>&nbsp;&nbsp;&#187;&nbsp;&nbsp; '
                + '          <i class="ico-sm mdi mdi-time" aria-hidden="true"></i> {date}'
                + '        </p>'
                + '        <div class="posts-body-content">'
                + '          {#block}<p class="alert alert-danger"><strong>提示:</strong> 作者被禁止发言或内容自动屏蔽</p>{/block}'
                + '          {^block}'
                + '            {&content}{&modify}'
                + '          {/block}'
                + '          <div class="mood-section" data-mood="{id}">'
                + '            <a href="javascript:;" title="支持" role="button" class="btn-light btn-sm mood-action" data-action="1" id="{id}-likes"><i class="mdi mdi-thumb-up" aria-hidden="true"></i></a>'
                + '            <a href="javascript:;" title="不赞同" role="button" class="btn-light btn-sm mood-action" data-action="2" id="{id}-hates"><i class="mdi mdi-thumb-down" aria-hidden="true"></i></a>'
                + '          </div>'
                + '        </div>'
                + '        <div class="posts-member-signature member-{author}-signature">{authorSignature}</div>'
                + '      </div>'
                + '    </div>'
                + '  </div>'
                + '</div>{/result}';
            var extRS = {
                modify: function () {
                    return this.modifyDate.length == 0 ? '' : '<p class="alert alert-warning">回复最近由 ' + this.modifyer + ' 于 ' + this.modifyDate + ' 编辑</p>';
                },
                APP: BASE
            };
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(obj, extRS);
            targetEleSelector.append(Mustache.render(T, rs));
            //图片的懒加载
            targetEleSelector.find('img.lazyload').lazyload();
        };
        //话题内容页中的
        tmp.buildRelateSectionTopic = function(json, element){
            var data ={};
                data.result = json;
            var T ='<p>相关的话题</p>'
                +'<ul>{#result}'
                +'<li>'
                +'  <sub>{ranking}</sub>'
                +'  <a href="{APP}{link}">{title}</a>'
                +'  <span class="d-none">{analogy}</span>'
                +'</li>'
                +'{/result}</ul>';
            
            Mustache.parse(T, ['{', '}']);
            $(element).append(Mustache.render(T, $.extend(data, {"APP":BASE})));
        };
        //会员中心的历史记录
        tmp.drawActionHistory = function (jsonArray) {
            var targetEleSelector = $('#member-home-actions');
            targetEleSelector.find('.home-record-item').remove();
            var obj = {};
            obj.result = jsonArray;
            var T = '{#result}'
                + ' <div class="home-record-item">'
                + '   <div class="record-item-body">'
                + '     <h6 class="record-item-heading"><a href="{APP}{link}">{title}</a></h6>'
                + '     <span>{actionTitle}&nbsp;&#187;&nbsp;{actionDate}</span>'
                + '   </div>'
                + ' </div>{/result}';
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(obj, { "APP": BASE });
            targetEleSelector.append(Mustache.render(T, rs));
        };
        //个人中心消息收件箱回调
        tmp.memberInboxTemplate = function (jsonArray) {
            var targetEleSelector = $('#member-message-records');
            var obj = {};
            obj.result = jsonArray;
            var T = '<ul class="media-list" style="padding: 10px 20px;">{#result}'
                + ' <li class="media letter-item">'
                + '   <div class="media-left mr-3">'
                + '     {#robot}<img style="width: 64px; height: 64px;" class="img-circle media-object" src="{APP}/member/avatar/0.png" title="message robot">{/robot}'
                + '     {^robot}<a href="{APP}{senderURI}"><img style="width: 64px; height: 64px;" class="img-circle media-object" src="{APP}/member/avatar/{sender}.png" title="{senderNickname}"></a>{/robot}'
                + '   </div>'
                + '   <div class="media-body">'
                + '     <h6 class="media-heading">{senderNickname} &nbsp;<span id="notice_{sender}" class="badge">0</span><span class="float-right"><i class="ico-sm mdi mdi-time"></i>&nbsp;{datetime}</span></h6>'
                + '     <div><a href="{APP}/message/view?sender={sender}" target="_blank">{subject}</a></div>'
                + '   </div>'
                + ' </li>{/result}</ul>';
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(obj, { "APP": BASE });
            targetEleSelector.append(Mustache.render(T, rs));
        };
        //个人中心消息发件箱回调
        tmp.memberOutboxTemplate = function (jsonArray) {
            var targetEleSelector = $('#member-message-records');
            var obj = {};
            obj.result = jsonArray;
            var T = '<ul class="media-list" style="padding: 10px 20px;">{#result}'
                + ' <li class="media letter-item">'
                + '   <div class="media-left mr-3">'
                + '     {#everyone}<img style="width: 64px; height: 64px;" class="img-circle media-object" src="{APP}/member/avatar/0.png" title="message robot">{/everyone}'
                + '     {^everyone}<a href="{APP}{receiverURI}"><img style="width: 64px; height: 64px;" class="img-circle media-object" src="{APP}/member/avatar/{receiver}.png" title="{receiverNickname}"></a>{/everyone}'
                + '   </div>'
                + '   <div class="media-body">'
                + '     <h6 class="media-heading">{&reces} &nbsp;<small>[{category}]</small><span class="float-right"><i class="ico-sm mdi mdi-time"></i>&nbsp;{datetime}</span></h6>'
                + '     <div class="letter-item-content">'
                + '       <p>{&content}</p>'
                + '     </div>'
                + '   </div>'
                + ' </li>{/result}</ul>';
            var extRS = {
                reces: function () {
                    var tmp = ''; var rs = this.receives;
                    for (var i = 0, len = rs.length; i < len; ++i) {
                        var rmid = rs[i].id;
                        var rmnm = rs[i].nickname;
                        tmp += '<a href="' + BASE + '/member/' + rmid + '.xhtml">' + rmnm + '</a>';
                        if (i < len - 1) {
                            tmp + '&nbsp;,&nbsp;';
                        }
                    }
                    return tmp;
                },
                APP: BASE
            };
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(obj, extRS);
            targetEleSelector.append(Mustache.render(T, rs));
        };
        //会员中心的话题|回复
        tmp.drawMHomeRecord = function (jsonArray) {
            var targetEleSelector = $('#member-home-records');
            targetEleSelector.find('.home-record-item').remove();
            var obj = {};
            obj.result = jsonArray;
            var T = '{#result}'
                + ' <div class="home-record-item">'
                + '   <div class="record-item-body">'
                + '     <h6 class="record-item-heading"><a href="{APP}{link}">{title}</a></h6>'
                + '     <span>楼主: <a href="{APP}{publisherURI}">{publisher}</a></span>'
                + '     <span>发布日期: {publishDate}</span>'
                + '     {#reply}'
                + '       <span>最近回复: <a href="{APP}{replierURI}">{replier}</a></span>'
                + '       <span>&#187; {replyDate}</span>'
                + '     {/reply}'
                + '   </div>'
                + ' </div>{/result}';
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(obj, { "APP": BASE });
            targetEleSelector.append(Mustache.render(T, rs));
        };
        //会员中心的点赞|收藏
        tmp.drawMHomeAction = function (jsonArray) {
            var targetEleSelector = $('#member-home-actions');
            targetEleSelector.find('.home-record-item').remove();
            var cancelURI = targetEleSelector.attr('data-action') || '#';
            var cancelCategory = targetEleSelector.attr('data-action-category') + '-topic' || null;
            var obj = {};
            obj.result = jsonArray;

            var T = '{#result}'
                + ' <div class="home-record-item">'
                + '   <div class="record-item-body">'
                + '     <h6 class="record-item-heading"><a href="{APP}{link}">{title}</a></h6>'
                + '     <span>操作日期: {actionDate}</span>'
                + '   </div>'
                + '   <div class="record-item-menu">'
                + '     <a class="action-cmd" role="button" href="javascript::" data-acctip="false" data-handler="{CU}" data-query="id:{id}" data-function="removeHomeCallbackFun" data-action="{MA}" data-action-key={AK}><i class="mdi mdi-delete"></i>&nbsp;删除</a>'
                + '   </div>'
                + ' </div>{/result}';
            var extRS = {
                AK: function () {
                    var rs = this.link; // /topic/%s.xhtml | javascript:;
                    if (rs.indexOf('/') !== -1) {
                        return rs.substring(7, rs.length - 6);
                    }
                    return null;
                },
                APP: BASE,
                CU: cancelURI,
                MA: cancelCategory
            };
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(obj, extRS);
            targetEleSelector.append(Mustache.render(T, rs));
        };
        //会员中心的版块收藏
        tmp.drawMHomeBoardRecord = function(jsonArray){
            var targetEleSelector = $('#member-home-boards');
            targetEleSelector.find('.home-record-item').remove();
            var cancelURI = targetEleSelector.attr('data-action') || '#';
            var cancelCategory = targetEleSelector.attr('data-action-category') || null;
            var obj = {};
                obj.result = jsonArray;
    
            var T ='{#result}'
                +' <div class="home-record-item">'
                +'   <div class="record-item-body">'
                +'     <h6 class="record-item-heading"><a href="{APP}{link}">{title}</a></h6>'
                +'     <span>{description}</span>'
                +'   </div>'
                +'   <div class="record-item-menu">'
                +'     <a class="action-cmd" role="button" href="javascript::" data-acctip="false" data-handler="{CU}" data-query="id:{id}" data-function="removeHomeCallbackFun" data-action="{MA}" data-action-key={AK}><i class="mdi mdi-delete"></i>&nbsp;取消</a>'
                +'   </div>'
                +' </div>{/result}';
            var extRS={
                AK : function(){
                      var rs = this.link; // /board/%s.xhtml | javascript:;
                      if(rs.indexOf('/') !== -1) {
                        return rs.substring(7, rs.length-6);
                      }
                      return null;
                },
                APP : BASE,
                CU : cancelURI,
                MA : cancelCategory
            };
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(obj, extRS);
            targetEleSelector.append(Mustache.render(T, rs));
        };
        //显示回复的点赞汇总结果
        tmp.drawMoodResult = function (json) {
            if ($.isEmptyObject(json.result)) {
                return;
            }
            $.each(json.result, function (index, item) {
                var pid = item.posts;
                if (item.likes !== '0') {
                    $('#' + pid + '-likes').append('<span>' + item.likes + '</span>');
                }
                if (item.hates !== '0') {
                    $('#' + pid + '-hates').append('<span>' + item.hates + '</span>');
                }
            });
        };
        // Message start
        // 聊天页中的历史记录[NW][8]
        tmp.drawLetterHistoryMessage = function (json, jqEle) {
            var T = ''
                + '<div class="media{#master} media-master{/master}" id="letter-{id}">'
                + '  <div class="media-avatar media-left">'
                + '    <a href="javascript:;">'
                + '        <img class="media-object img-circle" src="{APP}/member/avatar/{sender}.png" style="height:64px;width:64px;">'
                + '    </a>'
                + '  </div>'
                + '  <div class="media-body">'
                + '    <div class="media-bubble">'
                + '        <h6 class="media-heading"><small>{datetime}</small></h6>'
                + '        {#SM}<strong>{subject}</strong>{/SM}'
                + '        <p>{&body}</p>'
                + '    </div>'
                + '  </div>'
                + '</div>';
            var rs = {
                SM: function () {
                    return this.sender == 0;
                },
                APP: BASE
            };
            Mustache.parse(T, ['{', '}']);
            var ext = $.extend(json, rs);
            $(Mustache.render(T, ext)).insertAfter($('#' + jqEle).find('p.text-center'));
        };
        //chat界面的响应
        tmp.drawMessageItem = function (json) {
            if ($.isEmptyObject(json)) {
                return;
            }
            var T = ''
                + '<div class="media media-master" id="letter-{id}">'
                + '  <div class="media-avatar media-left">'
                + '    <a href="javascript:;">'
                + '        <img class="media-object img-circle" src="{APP}/member/avatar/{sender}.png" style="height:64px;width:64px;">'
                + '    </a>'
                + '  </div>'
                + '  <div class="media-body">'
                + '    <div class="media-bubble">'
                + '        <h6 class="media-heading"><small>{datetime}</small></h6>'
                + '        <p>{body}</p>'
                + '    </div>'
                + '  </div>'
                + '</div>';

            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(json, { "APP": BASE });
            var targetEleSelector = '#message-' + json.receiver + '-box';
            $(targetEleSelector).append(Mustache.render(T, rs)).scrollTop($(targetEleSelector)[0].scrollHeight);
            $('#send-message-form').find('.form-control').val('');
            $('#send-message-form').find('.send-message-action').removeClass('disabled');
        };

        //Threads start
        //话题内容页中会员弹出菜单的内容
        tmp.buildMemberProfileMenu = function (json, jqEle) {
            var MP = ''
                + '<div class="popmenu-member-header member-bg-{label}">'
                + '  <div class="popmenu-member-header-avatar"><img src="{APP}/member/avatar/{id}.png" class="img-circle" width="64px" height="64px" /></div>'
                + '  <div class="popmenu-member-header-info">'
                + '    <h6>{nickname}</h6>'
                + '    <p class="txt-sm">{levelNo}级 / {level}</p>'
                + '  </div>'
                + '</div>'
                + '<div class="popmenu-member-body">'
                + '  <ul class="list-inline"><li class="list-inline-item">{score}<span>积分</span></li><li class="list-inline-item">{threads}<span>主题</span></li><li class="list-inline-item">{replies}<span>回复</span></li></ul>'
                + '</div>'
                + '<div class="popmenu-member-footer">'
                + '  <a href="{APP}/member/{id}.xhtml" title="会员个人中心" role="button" class="btn btn-light btn-sm">'
                + '    <i class="ico-sm mdi mdi-home" aria-hidden="true"></i> 个人中心'
                + '  </a>'
                + '  <a href="javascript:;" title="发送消息" data-handler="{APP}/message/transmit?receiver={id}&names={nickname}" role="button" class="btn btn-light btn-sm message-transmit">'
                + '    <i class="ico-sm mdi mdi-email" aria-hidden="true"></i> 短消息'
                + '  </a>'
                + '</div>'
            var menuContent = '正在努力加载中...';
            if (!$.isEmptyObject(json)) {
                Mustache.parse(MP, ['{', '}']);
                var rs = $.extend(json, { "APP": BASE });
                menuContent = Mustache.render(MP, rs);
            }
            var linkDefaultWhiteList = $.fn.popover.Constructor.Default.whiteList;
            linkDefaultWhiteList.a = ['target', 'href', 'title', 'rel', 'data-handler'];
            jqEle.popover({
                placement: 'right',
                title: '',
                trigger: 'focus',
                html: true,
                content: menuContent
            });
            jqEle.popover('show');
        };
        //快速回复的异步回调函数
        tmp.quickReplyFillPosts = function (json) {
            var T = ''
                + '<div class="topic_posts dynamic-posts-record fadeout-anim">'
                + '  <div class="topic_posts_item">'
                + '    <dl class="topic_posts_item_left" data-handler="{APP}/member/profile.json?id={author}">'
                + '      <dt style="padding-top: 20px;padding-left: 20px;width:180px">'
                + '        <div class="posts-member-avatar">'
                + '          <a href="javascript:;" class="avatar poper-member-menu">'
                + '            <img class="avatar" src="{APP}/member/avatar/{author}.png" alt="User avatar" />'
                + '          </a>'
                + '        </div>'
                + '        <a href="{APP}/member/{author}.xhtml" class="member-info"> <span class="member-{author}-label member-{authorStyle}">{authorNames}</span></a>'
                + '      </dt>'
                + '      <dd>{authorGroup}</dd>'
                + '      {#master}<dd><small class="badge badge-dark">楼主</small></dd>{/master}'
                + '    </dl>'
                + '    <div class="topic_posts_item_right">'
                + '      <div id="posts-{id}" class="posts-body">'
                + '        <ul class="posts-buttons">'
                + '          <li><a href="javascript:;" class="action-cmd delete-post" data-handler="{APP}/posts/delete" data-query="id:{id}"><i class="ico-sm mdi mdi-delete" aria-hidden="true"></i><span>删除</span></a></li>'
                + '          <li><a href="javascript:;" class="post-action-quote" data-handler="{APP}/posts/quote/data.json" data-query="id:{id}"><i class="ico-sm mdi mdi-quote"></i><span>回复</span></a></li>'
                + '          <li><a href="javascript:;" class="post-action-report" data-handler="{APP}/posts/report" data-query="id:{id}"><i class="ico-sm mdi mdi-flag"></i><span>举报</span></a></li>'
                + '          <li><a name="#posts-{id}">{floor}<sup>#</sup></a></li>'
                + '        </ul>'
                + '        <p class="posts-member">'
                + '          <a href="{APP}/member/{author}.xhtml">{authorNames} @u{author}</a>&nbsp;&nbsp;&#187;&nbsp;&nbsp; '
                + '          <i class="ico-sm mdi mdi-time" aria-hidden="true"></i> {date}'
                + '        </p>'
                + '        <div class="posts-body-content">'
                + '          {&content}'
                + '          <div class="mood-section" data-mood="{id}">'
                + '            <a href="javascript:;" title="支持" role="button" class="btn-light btn-sm mood-action" data-action="1" id="{id}-likes"><i class="mdi mdi-thumb-up" aria-hidden="true"></i></a>'
                + '            <a href="javascript:;" title="不赞同" role="button" class="btn-light btn-sm mood-action" data-action="2" id="{id}-hates"><i class="mdi mdi-thumb-down" aria-hidden="true"></i></a>'
                + '          </div>'
                + '        </div>'
                + '        <div class="posts-member-signature member-{author}-signature">{authorSignature}</div>'
                + '      </div>'
                + '    </div>'
                + '  </div>'
                + '</div>';
            Mustache.parse(T, ['{', '}']);
            var rs = $.extend(json, { "APP": BASE });
            $('#topic_posts_collect').append(Mustache.render(T, rs));
            //图片的懒加载
            $('#posts-' + json.id).find('img.lazyload').lazyload();
        };
        tmp.poperNotice = function (json) {
            if ($.isEmptyObject(json)) {
                return;
            }
            var TC = '{#result}'
                + '<div class="toast ml-auto" role="alert" data-delay="700" data-autohide="false">'
                + '  <div class="toast-header">'
                + '    <strong class="mr-auto text-primary">{nickname}</strong>'
                + '    <small class="text-muted">{pubdate}</small>'
                + '    <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">'
                + '      <span aria-hidden="true">×</span>'
                + '    </button>'
                + '  </div>'
                + '  <div class="toast-body">{content}</div>'
                + '</div>{/result}';
            var obj = {}; obj.result = json;
            Mustache.parse(TC, ['{', '}']);
            var rs = $.extend(obj, { "APP": BASE });
            $('#toast-collect').append(Mustache.render(TC, rs));
            $('.toast').toast('show');
        };
        return tmp;
    })();
    return jForumTemplate;
});